%% Optimal Policy Models under Discretion and Commitment
%
% This tutorial describes how to use IRIS to calculate two basic types of
% optimal policies, discretion and commitment, and run various types of
% experiments with models based on them. The experiments include
% simulating shocks, simulation disinflation, and drawing policy frontiers
% to describe policy trade-offs.

%% How to Best Run This Tutorial?
%
% Each m-file in this tutorial is split into what is called "code sections"
% in Matlab. A code cell is a shorter block of code performing a specific
% task, separated from other code cells by a double percent sign, `%%`
% (usually with a title and brief introduction added). By default, the
% cells are visually separated from each other by a horizontal rule in the
% Matlab editor.
%
% Instead of running each m-file from the command window, or executing this
% `read_me_first` as a whole, do the following. Open one tutorial m-file in
% the Matlab editor. Arrange the editor window and the command window next
% to each other so that you can see both of them at the same time. Then run
% the m-file cell by cell. This will help you watch closely what exactly
% is going on.
%
% To execute one particular cell, place the cursor in that cell (the
% respective block of code will get highlighted), and select "Run Current
% Section" from a contextual menu (upon a right click on the mouse), or
% pressing a keyboard shortcut (which differ on different systems and
% Matlab versions). To learn more on code sections, search Matlab
% documentation for "code section".

clc;

%% Simple Optimal Policy Model File
%
% This is the model file (i.e. description of the variables and equations)
% for a simple optimal policy exercise. The model has a simple aggregate
% demand equation, a Phillips curve, and two verions of monetary policy
% specification: (1) a simple rule, and (2) a loss function used to
% calculate optimal policy. Choose between the two specifications using the
% switch `optimal_policy`. Furthermore, given the loss function, the type
% of optimal policy calculated in IRIS can be either optimal discretionary
% policy, or optimal commitment policy. Use the option `'optimal='` at the
% time of loading the model file (i.e. in the function `model`) to choose
% one or the other.

edit optimal_policy.model;

%% Read and Solve Models with Optimal Policy
%
% Load the model file `optimal_policy.model` and create three different
% versions of it: a model with a simple policy rule, an optimal
% discretionary (time-consistent) policy model, and an optimal commitment
% policy model. Calibrate, solve and save the model objects for further
% use.

% edit read_model.m;
read_model;

%% Simulate Simple Shocks with Optimal Policy Models
%
% Run three shock simulations: a demand shock, an anticipated future demand
% shock, and a cost-push shock, to illustrate the performance of the three
% versions of the model (a simple rule, discretionary policy, commitment
% policy). Simulate the shocks also with loss functions that only include
% inflation to show that monetary policy can be much more effective in
% accommodating demand shocks that in offsetting cost-push shocks.

% edit simulate_shocks.m;
simulate_shocks;

%% Simulate Disinflation in Optimal Policy Models
%
% Simulate a permanent disinflation in the three types of models (a simple
% rule, discretionary policy, commitment policy). This experiment shows one
% of the possible ways how to simulate a permament change in the steady
% state of a model. It also illustrates the real cost associated with
% disinflation under different policy assumptions, measured by the
% sacrifice ratio.

% edit simulate_disinflation.m;
simulate_disinflation;

%% Draw Policy Frontier
%
% Calculate the asymptotic std deviations of inflation and output under
% discretionary and commitment policies for a range of different weights on
% output in the loss function. Use the calculated points to draw policy
% frontiers epicting trade-offs faced by the central bank, and compare them
% for the two types of policies.

% edit draw_policy_frontier.m;
draw_policy_frontier;

%% Publish Tutorial Files to PDFs
%
% The following commands can be used to create PDF versions of the tutorial
% files:

%{
    latex.publish('read_me_first.m',[],'evalCode=',false);
    latex.publish('optimal_policy.model');
    latex.publish('read_model.m');
    latex.publish('simulate_shocks.m');
    latex.publish('simulate_disinflation.m');
    latex.publish('draw_policy_frontier.m');
%}
